<?php
declare(strict_types=1);

namespace Plugin\Alarm\Http\Controller\Api;

use Plugin\Alarm\Service\RdAlarmDangerService;
use Plugin\Alarm\Http\Request\Admin\RdAlarmDangerRequest;
use Plugin\Alarm\Schema\RdAlarmDangerSchema;
use App\Http\Admin\Middleware\PermissionMiddleware;
use App\Http\Common\Middleware\AccessTokenMiddleware;
use App\Http\Common\Middleware\OperationMiddleware;
use App\Http\Common\Result;
use App\Http\CurrentUser;
use Hyperf\HttpServer\Request;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\Swagger\Annotation\Delete;
use Hyperf\Swagger\Annotation\Get;
use Hyperf\Swagger\Annotation\HyperfServer;
use Hyperf\Swagger\Annotation\JsonContent;
use Hyperf\Swagger\Annotation\Post;
use Hyperf\Swagger\Annotation\Put;
use Hyperf\Swagger\Annotation\RequestBody;
use Mine\Access\Attribute\Permission;
use Mine\Swagger\Attributes\PageResponse;
use App\Http\Admin\Controller\AbstractController as AdminAbstractController;

/**
 * 隐患信息控制器
 * Class RdAlarmDangerApiController
 */
#[HyperfServer(name: 'http')]
final class RdAlarmDangerApiController extends AdminAbstractController
{
    /**
     * 业务处理服务
     * RdAlarmDangerService
     */
    public function __construct(
        protected readonly RdAlarmDangerService $service,
        protected readonly CurrentUser $currentUser
    ) {}

    #[Post(
        path: '/alarm/rdAlarmDanger/api/ai',
        operationId: 'AlarmRdAlarmDangerCreate',
        summary: 'AI发现隐患',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['隐患类别'],
    )]
    #[PageResponse(instance: new Result())]
    public function aiReport(Request $request): Result
    {
        $this->service->Report(array_merge($request->post(), [
            'created_by' => 0,
            'work_type' => 2,
            'from_type' => 1
        ]));
        return $this->success();
    }

    #[Post(
        path: '/alarm/rdAlarmDanger/api',
        summary: '创建隐患信息',
        security: [['Bearer' => [], 'ApiKey' => []]],
        tags: ['隐患类别'],
)]
    #[PageResponse(instance: new Result())]
    #[Middleware(middleware: AccessTokenMiddleware::class, priority: 100)]
    public function manualReport(RdAlarmDangerRequest $request): Result
    {
        $this->service->Report(array_merge($request->post(), [
            'created_by' => $this->currentUser->id(),
            'work_type' => 3,
        ]));
        return $this->success();
    }

}